package cn.demoncat.util.quartz;

import cn.demoncat.util.quartz.constant.JobConstant;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobKey;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;

/**
 * JobBean
 * 
 * @author 延晓磊
 *
 * @since 2017年9月13日
 */
public class JobBean extends QuartzJobBean {

	@Resource
	private JobExecutor jobExecutor;

	/**
	 * 任务调度
	 * 
	 * @param context
	 * @author 延晓磊
	 *
	 * @since 2017年9月14日
	 *
	 */
	@Override
	public void executeInternal(JobExecutionContext context) {
		// 获取group-id和job-id
		JobKey jobKey = context.getTrigger().getJobKey();
		String groupId = jobKey.getGroup();
		String jobName = jobKey.getName();
		Long jobId = Long.valueOf(jobName);
		// 获取任务附带参数
		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
		// 执行任务/[记录日志、添加监控]/通知远程系统执行
		jobExecutor.execute(groupId, jobId, jobDataMap.getString(JobConstant.HANDLER), jobDataMap.getString(JobConstant.PARAMS));
	}

}